package com.xyazm.order.controller;


import com.xyazm.order.domain.dto.CreateOrderDTO;
import com.xyazm.order.domain.dto.GenOrderIdDTO;
import com.xyazm.order.domain.dto.PrePayOrderDTO;
import com.xyazm.order.domain.param.*;
import com.xyazm.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author xuyou
 * @since 2022-04-09
 */
@RestController
@RequestMapping("/order")
public class OrderController {


    @Autowired
    private IOrderService orderService;

    /**
     * 生成订单号
     * @return
     */
    @PostMapping("/genOrderId")
    public GenOrderIdDTO genOrderId(@Valid @RequestBody GenOrderIdParam param) {
        String orderId = orderService.genOrderId(param);
        return new GenOrderIdDTO(orderId);
    }

    /**
     * 创建订单
     * @return
     */
    @PostMapping("/createOrder")
    public CreateOrderDTO createOrder(@Valid @RequestBody CreateOrderParam param) {
        CreateOrderDTO createOrderVO = orderService.createOrder(param);
        return createOrderVO;
    }

    /**
     * 预支付订单
     * @author xuyou
     * 2022/6/16 0016 20:57
    */
    @PostMapping("/prePayOrder")
    public PrePayOrderDTO prePayOrder(@Valid @RequestBody PrePayOrderParam param) {
        PrePayOrderDTO prePayOrderDTO = orderService.prePayOrder(param);
        return prePayOrderDTO;
    }


    /**
     * 支付回调
     * @author xuyou
     * 2022/6/21 0021 22:41
    */
    @PostMapping("/payCallback")
    public void payCallback(@RequestBody PayCallbackParam param) {
        orderService.payCallback(param);
    }

    /**
     * 移除订单
     * @author xuyou
     * 2022/6/21 0021 22:42
    */
    @PostMapping("/removeOrders")
    public void removeOrders(@RequestBody RemoveOrderParam param) {
        orderService.removeOrders(param);
    }

    /**
     * 调整收货地址
     * @author xuyou
     * 2022/6/21 0021 22:38
    */
    @PostMapping("/adjustDeliveryAddress")
    public void adjustDeliveryAddress(@RequestBody AdjustDeliveryAddressParam param) {
        orderService.adjustDeliveryAddress(param);
    }




}
